package TCP;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package test
 * @date 2024/4/10 上午10:05
 */
public class Day10_Server_Thread {
    //动态数组：存储所有上线的socket
    public static ArrayList<Socket> onLineSockets = new ArrayList<>();
    //把socket存储到动态数组中


    //服务器启动

    public static void main(String[] args) {
        try {
            ServerSocket ss = new ServerSocket(8888);
            System.out.println("服务器启动成功");
            while (true) {
                Socket accept = ss.accept();
                onLineSockets.add(accept);
                System.out.println(accept.getRemoteSocketAddress() + "上线了");
                //收到一个链接就创建一个线程
                Day10_Server_Thread_outclass day10_server_thread_outclass = new Day10_Server_Thread_outclass(accept);
                Thread t = new Thread(day10_server_thread_outclass);
                t.start();
            }


        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
